/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package researchgrants.parts.GrantRequest.statusChanges;

import java.awt.Container;
import java.awt.Window;
import researchgrants.parts.LoggedData.LoggedData;
import researchgrants.parts.LoggedData.panels.LoggedDataPanels;
import javax.swing.event.ChangeListener;
import researchgrants.parts.panelsManager.LoggedDataPanelsManager;

/**
 * An abstract view of a Status Change.
 * @author DOStudent1
 */
public abstract class GrantRequestStatusChangeView extends javax.swing.JPanel {
    
    
    // facilitate adding LoggedDataPanels to this StatusChange
    protected static LoggedDataPanelsManager createLoggedDataPanelManager(boolean isMandatory, boolean isNew, LoggedDataPanels panels, Window parentWindow, LoggedData data, Container fieldContainer) {
        return(createLoggedDataPanelManager(isMandatory, isNew, panels, parentWindow, data, fieldContainer, null));
    }
    
    protected static LoggedDataPanelsManager createLoggedDataPanelManager(boolean isMandatory, boolean isNew, LoggedDataPanels panels, Window parentWindow, LoggedData data, Container fieldContainer, ChangeListener changeEventListener) {
        LoggedDataPanelsManager loggedDataPanelsManager =new LoggedDataPanelsManager();
        loggedDataPanelsManager.setMandatory(isMandatory);
        loggedDataPanelsManager.startAsNew(isNew);
        {
            panels.setParent(parentWindow, loggedDataPanelsManager);
            if (changeEventListener!=null) {
                panels.addChangeListener(changeEventListener);
            }
            if (!isNew) {
                panels.setData(data);
            }
            loggedDataPanelsManager.setPanels(panels);
        }
        fieldContainer.removeAll();
        fieldContainer.add(loggedDataPanelsManager);
        loggedDataPanelsManager.display();   
        return (loggedDataPanelsManager);
    }

    
    // Saves a LoggedData
    protected static int saveLoggedDataPanelsManagerData(LoggedDataPanelsManager loggedDataPanelsManager) {
            ((LoggedDataPanelsManager)loggedDataPanelsManager).saveData();
            return(((LoggedDataPanels)(((LoggedDataPanelsManager)loggedDataPanelsManager).getPanels())).getData().getId());
    }
    
    
    // displays the StatusChange View
    public void display() {
        setVisible(true);
    }
}
